/**
 * Created by Administrator on 2017/3/13 0013.
 */
var Page0= {
    create: function () {
        var page = {};

        var t0,t1;

        page.ui = new PIXI.DisplayObjectContainer();

        var bg = new PIXI.Sprite(resource['assets/images/p0_bg.png'].texture);
        bg.anchor.set(0.5);
        bg.x=740/2-10;
        bg.y=1136/2;
        page.ui.addChild(bg);

        var t0=new PIXI.Sprite(resource['assets/images/p0_t0.png'].texture);
        t0.x=370;
        t0.y=550;
        t0.alpha=0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);
        // console.log(t0.texture.width);

        var t1=new PIXI.Sprite(resource['assets/images/p0_t1.png'].texture);
        t1.x=370;
        t1.y=627;
        t1.alpha=0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        var tip= new PIXI.Sprite(resource['assets/images/tip.png'].texture);
        tip.x = 370;
        tip.y = 1105;
        tip.alpha = 1;
        tip.anchor.set(0.5);
        page.ui.addChild(tip);
        TweenMax.to(tip,0.7,{y:1105-30,ease:Cubic.easeInOut,yoyo:true,repeat:-1});


        page.ui.addChild(pd.emitterContainer);

        var mouseDownPT={x:0,y:0};
        var targetStartPT={x:0,y:0};
        var bool_down=false;
        page.ui.interactive=true;
        page.ui.on('pointerdown',downHandler);
        page.ui.on('pointerup', upHandler)
        page.ui.on('pointermove',moveHandler);
        function downHandler(e) {
            console.log('ddddddd')
            bool_down=true;
            mouseDownPT.x = e.data.global.x;
            mouseDownPT.y = e.data.global.y;
        }
        function upHandler(e) {
            bool_down=false;
        }
        function moveHandler(e) {
            if(bool_down)
            {
                console.log(Math.abs(e.data.global.y-mouseDownPT.y))
                if(Math.abs(e.data.global.y-mouseDownPT.y)>40)
                {
                    bool_down=false;
                    page.myOut();
                }
            }
        }

        page.In=function () {
            TweenMax.killTweensOf(t0);
            TweenMax.killTweensOf(t1);

            t0.x=370+100;
            t1.x=370-100;
            t0.alpha=t1.alpha=0;
            TweenMax.to(t0,1,{delay:0.5,x:370,alpha:1,ease:Cubic.easeInOut});
            TweenMax.to(t1,1,{delay:0.5,x:370,alpha:1,ease:Cubic.easeInOut});
        }
        page.Out=function () {

        }
        page.myOut=function () {
            page.ui.interactive=false;
            var evt=new CustomEvent('Game_ScrollIn');
            document.dispatchEvent(evt);
            document.dispatchEvent(evt);
            TweenMax.to(t0,1,{delay:0.1,x:370+100,alpha:0,ease:Cubic.easeInOut});
            TweenMax.to(t1,1,{delay:0.1,x:370-100,alpha:0,ease:Cubic.easeInOut});

            TweenMax.to(tip,1,{alpha:0.0,ease:Cubic.easeInOut});
            TweenMax.to(bg,1.75,{alpha:0.0,ease:Cubic.easeInOut});
            TweenMax.to(bg.scale,3.5,{x:3.5,y:3.5,ease:Cubic.easeOut,onComplete:function () {
                var evt=new CustomEvent('Game_Page0Out');
                document.dispatchEvent(evt);
            }});
        }
        return page;
    }
}